﻿@{
    ViewBag.Title = "RoleUser";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script type="text/javascript" src="/Res/MyJs.js"></script>
<style type="text/css">
    .Competop
    {
        width: 880px;
        background: #ffffff;
        border: lightskyblue 1px solid;
        margin:5px 0px 0px 5px;
    }
    .Compeleft
    {
        width: 100%;
        height: 300px;
        float: left;
        border: lightskyblue 1px solid;
        overflow-y: scroll;
    }
</style>
<script type="text/javascript">
    $(function () {
        var id = window.location.href;
        if (id.indexOf("?") > -1) {
            id = id.split("?")[1];
            if (id.indexOf("=") > -1) {
                id = id.split("=")[1];
            }
        }
        $("#txt_RoleID").val(id);
        $("#DataGrid").datagrid({
            width: 400,
            height: 490,
            autoRowHeight: false,
            fitColumns: true,
            pagination: true,
            pageSize: 15,
            pageList:[15],
            queryParams: {},
            title: '选择用户',
            url: "/SysUser/UserList/",
            idField: "Guid",
            columns: [[
            { field: 'GUID', checkbox: true },
            { field: 'EmployeeCode', title: '工号', width: 100 },
            { field: 'EmployeeName', title: '姓名', width: 100 },
            { field: 'Username', title: '用户名', width: 100 }
             ]]
        });
        $.post("/SysRole/selectUser/?id=" + encodeURI(id), function (res) {
            $("#selectView").append(res);

        });
        var queryParams = $('#DataGrid').datagrid('options').queryParams;
        queryParams.state = jv.GetDivJson($(".search"), 4);
        $('#DataGrid').datagrid('options').queryParams = queryParams;
        $("#DataGrid").datagrid('reload');
    });

    function back() {
        window.location.href = "/SysRole/RoleList";
    }
    function seach() {
        var queryParams = $('#DataGrid').datagrid('options').queryParams;
        queryParams.state = jv.GetDivJson($(".search"), 4);
        $('#DataGrid').datagrid('options').queryParams = queryParams;
        $("#DataGrid").datagrid('reload');
    }
    var arrID = new Array();
    function InInfo() {
        var checkedData = $("#DataGrid").datagrid("getChecked");
        if (checkedData.length > 0) {
            for (var i = 0; i < checkedData.length; i++) {
                var uid = checkedData[i].Guid;
                if (arrID.indexOf(uid) == -1) {
                    arrID.push(uid);
                    var uname = checkedData[i].EmployeeName;
                    var ucode = checkedData[i].Username;
                    var html = "<tr id='tr1" + uid + "'><td><input type=\"checkbox\" id=\""
                + uid + "\" value=\"" + uid + "," + uname + "," + ucode
                 + "\" name=\"" + uid + "," + uname + "," + ucode + "\" class=\"" + ucode + "\" /></td><td>" + uname + "</td><td>" + ucode + "</td></tr>";

                    $("#selectView").append(html);
                }
            }
        } else {
            alert("请选择用户！");
            return false;
        }
    }
    function OutInfo() {
        var selector = $("#selectView input:checked");
        selector.each(function (i, d) {
            $("#tr1" + d.id).remove();
            arrID.removeValue(d.id);
        });
    }
    function select_All() {
        var selector = $("#selectView input");
        if ($("#select_All").is(':checked')) {
            selector.each(function () {
                if (!($(this).attr("disabled") == "disabled"))
                    $(this).attr("checked", "checked");
            });
        }
        else {
            selector.removeAttr("checked");
        }
    }
    function SaveDate() {
        var id = window.location.href;
        if (id.indexOf("?") > -1) {
            id = id.split("?")[1];
            if (id.indexOf("=") > -1) {
                id = id.split("=")[1];
            }
        }
        $.post("/SysRole/SaveRoleUser?id=" + encodeURI(id), { query: jv.GetDivJson($("#selectView")) }, function (res) {
            window.location.href = "/SysRole/RoleList";
        });
    }
</script>
<div class="Competop">
    <table style="width: 100%" class="search">
        <tr>
            <td style="width: 30%; text-align: left">
                <input id="txt_Company" type="hidden" />
                <input id="txt_Department" type="hidden" />
                <input id="txt_Post" type="hidden" />
                <input id="txt_Status" type="hidden" value="0" />
                <input id="txt_EmployeeName" type="hidden" />
                用户名：<input id="txt_UserName" type="text" class="inputSearch" style="width: 160px;" />
                <input id="txt_RoleID" type="hidden" />
                <input id="ddl_UserType" type="hidden" value="-1" />
                <input type="button" value="搜索" onclick="seach()" />
            </td>
            <td style="width: 30%; text-align: right">
                <input type="button" value="保存" onclick="SaveDate()" />
                <input type="button" onclick="back()" value="返回" />
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>
                <table id="DataGrid">
                </table>
            </td>
            <td valign="middle" align="center" style="width: 50px;">
                <input type="button" value=" 添加 " onclick="InInfo()" />
                <br /><br />
                <input type="button" value=" 删除 " onclick="OutInfo()" />
            </td>
            <td valign="top" style="width: 430px; overflow-y: scroll; border: lightskyblue 1px solid;">
                <div class="tab_title">
                    <div class="tab_text">
                        配置组用户</div>
                </div>
                <table id="selectView" width="100%" class="table_border" border="0" cellpadding="0"
                    cellspacing="0">
                    <tr class="table_head">
                        <td width="25">
                            <input id="select_All" type="checkbox" onclick="select_All();" />
                        </td>
                        <td>
                            用户名
                        </td>
                        <td>
                            帐号
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
